import _ from 'lodash';
import { materialList } from '../material/index';
import { useProjectStore } from '@/store';
import {
  getRemConversion,
  getExhibitsHeight,
  addExhibitsItemPosition,
  getFallbackType,
  collisionDetection,
  setcollisionArr,
  groupPostionCalculate,
  getMOdeListArr,
} from '@/utils/getRemComputed';
/**
 * 配置大纲各级展品初始化数据
 */

export const getComputeIndex = (list: any, info: any, moveStarX: number, moveStarWidth: number, indexs: number) => {
  let maxPosition = moveStarX + moveStarWidth;
  let ShowpieceList = _.cloneDeep(list);

  let metathesis = {
    collisionIndex: -1,
    position: -1,
  };
  let remX = getRemConversion(info.x);
  ShowpieceList.forEach((element, index) => {
    if (index !== indexs) {
      if (remX > moveStarX) {
        metathesis.position = 2;
        // console.log('向右',remX,moveStarX)
        //判断当前是向右移动
        if (
          remX + moveStarWidth / 2 < element.x + element.width &&
          remX + moveStarWidth / 2 > element.x &&
          remX + moveStarWidth / 2 > element.x + element.width / 2 &&
          remX + moveStarWidth / 2 < element.x + element.width
        ) {
          // console.log('判断向又越过中线');
          metathesis.collisionIndex = index;
        }
      } else if (remX < moveStarX) {
        // console.log('向左')
        metathesis.position = 1;
        //判断是向左移动
        if (
          remX + moveStarWidth / 2 < element.x + element.width &&
          remX + moveStarWidth / 2 > element.x &&
          remX + moveStarWidth / 2 < element.x + element.width / 2
          // remX + (moveStarWidth / 2) <= element.x + (element.width / 2) &&
          // remX + (moveStarWidth / 2) > element.x + element.width
        ) {
          metathesis.collisionIndex = index;
          // console.log('判断向左越过中线');
        }
      }
    }
  });

  return metathesis;
};
export const settemplateListStyle = (list: any) => {
  const store = useProjectStore();
  // console.log(materialList, store.modeId);
  //配置大纲样式以及展品样式
  // let OutlineList = _.cloneDeep(list);
  // OutlineList.forEach((level1) => {
  //   level1.children.forEach((level2) => {
  //     level2.children.forEach((level3) => {});
  //   });
  // });
};

export const settemplateListAuxiliaryStyle = (list: any) => {
  //配置辅助信息样式以及展品样式
  let auxiliaryList = _.cloneDeep(list);
};
export const setShowpieceListStyle = (list) => {
  const ShowpieceList = _.cloneDeep(list);
};
export const HistoryListType = (indexList, type, oldList) => {
  //修改历史存储的type值
  const ShowpieceList = _.cloneDeep(oldList);
  return oldList;
};
export const isElementInViewportOrNearby = (el, scrollParent, homeScrollLeft) => {
  // 获取元素的边界信息 计算元素是否应该显示提升性能
  if (!scrollParent) {
    return true;
  }
  const viewportWidth = window.innerWidth + 200;
  const rect = el.getBoundingClientRect();
  const scrollParentRect = scrollParent.getBoundingClientRect();
  let distanceLeft = rect.left - scrollParentRect.left + scrollParent.scrollLeft; //当前元素距离父级滚动元素距离
  //viewportWidth 屏幕宽度
  let elRigth = rect.width + distanceLeft; //元素右侧极限位置
  //计算右侧元素应该显示  homeScrollLeft+viewportWidth>distanceLeft
  //计算左侧原始是否应该显示  elRigth-viewportWidth>homeScrollLeft
  // console.log(elRigth > homeScrollLeft - viewportWidth || homeScrollLeft - viewportWidth < distanceLeft, '获取当前');
  if (homeScrollLeft + viewportWidth > distanceLeft && elRigth + viewportWidth > homeScrollLeft) {
    return true;
  } else {
    return false;
  } 
  // return distanceLeft;
  // return true;
};
export const ShowcaseItemTransform = (x: number, width, ShowcaseWidth) => {
  //x左偏移 width 展品宽度  ShowcaseWidth 展牌宽度
  //获取展品展牌左侧距离
  let leftNumber = (width - ShowcaseWidth) / 2; //获取左侧偏移距离
  let defaultValue = x + leftNumber;
  return defaultValue;
};
